<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      @import url('https://fonts.googleapis.com/css?family=Poppins:400,700,900');
    </style>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      header,
      footer {
        height: 100vh;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 50px;
        font-family: 'poppins-bold', sans-serif !important;
      }
      main {
        height: 200vh;

        background-color: blue;
        position: relative;
      }
      main > .animate_content {
        position: sticky;
        top: 0;
        left: 0;
        height: 100vh;
        background-color: yellow;
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
      }
      .list {
        display: flex;
        flex-wrap: wrap;
        max-width: 1200px;
        margin: 0 auto;
        align-items: center;
        justify-content: center;
      }
      .list-item {
        width: 13.28571%;
        height: 60px;
        margin: 20px 0;
        display: flex;
        align-items: center;
        justify-content: center;
      }
      .list-item > div {
        width: 60px;
        background-color: red;
        border-radius: 16px;
        height: 100%;
      }
    </style>
  </head>
  <body>
    <header>Header</header>
    <main>
      <div class="animate_content">
        <div class="list">
          <div class="list-item">
            <div></div>
          </div>
          <div class="list-item">
            <div></div>
          </div>
          <div class="list-item">
            <div></div>
          </div>
          <div class="list-item">
            <div></div>
          </div>
          <div class="list-item">
            <div></div>
          </div>
          <div class="list-item">
            <div></div>
          </div>
          <div class="list-item">
            <div></div>
          </div>
          <div class="list-item">
            <div></div>
          </div>
          <div class="list-item">
            <div></div>
          </div>
          <div class="list-item">
            <div></div>
          </div>
          <div class="list-item">
            <div></div>
          </div>
          <div class="list-item">
            <div></div>
          </div>
          <div class="list-item">
            <div></div>
          </div>
          <div class="list-item">
            <div></div>
          </div>
        </div>
      </div>
    </main>
    <footer>Footer</footer>
    <script>
      const animate_content = document.querySelector('.animate_content');
      // 获取元素到可视窗口的位置信息
      const rect = animate_content.getBoundingClientRect();

      function createAnimate(scrollStart, scrollEnd, valueStart, valueEnd) {
        const scrollTop = document.documentElement.scrollTop;
        if (scrollTop >= scrollStart && scrollTop <= scrollEnd) {
          console.log('abab');
        }
      }
      window.addEventListener('scroll', function (e) {
        const opacity = createAnimate(rect.top, rect.bottom, 0, 1);
      });
    </script>
  </body>
</html>
